
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Contact extends Menu_Controller {
    public function __construct()
    {
        parent::__construct();
        $this->load->Model('Contact_model');
        $this->load->Model('Menu_model');
        $this->load->Model('Contents_model');
        $this->load->library('ajaxMsgModel');
        $this->load->library('form_validation');

    }


    public function contactmsginfo()
    {
        $this->ajaxmsgmodel->Type='1';
        $this->Ajax_Check($this->ajaxmsgmodel);

        $menuid=$this->uri->segment(4);
        $data['menuid']=$menuid;
        $data['crumbs_items']=$this->get_crumbs_content_menu($menuid);
        $data['contactModel']=$this->Contact_model->get_first_row_by_menuid($menuid);
        $this->load->view('admin/contact/contactinfo.html',$data);
    }

    public function edit_contact()
    {
        $this->ajaxmsgmodel->Type='4';
        $this->Ajax_Check($this->ajaxmsgmodel);

        $this->load->library('ajaxMsgModel');
        $contactModel=new $this->Contact_model();

        $contactModel->conpany_name=$this->input->post('conpany_name');
        $contactModel->address=$this->input->post('address');
        $contactModel->menuid=$this->input->post('menuid');
        $contactModel->qq=$this->input->post('qq');
        $contactModel->tel=$this->input->post('tel');
        $contactModel->fax=$this->input->post('fax');
        $contactModel->email=$this->input->post('email');
        $contactModel->phone=$this->input->post('phone');
        $parent_menu_model=$this->Menu_model->get_menu_by_id($contactModel->menuid);
        $back_url=site_url('admin/'.$parent_menu_model->menu_control.'/'.$parent_menu_model->menu_action.($parent_menu_model->page_type==1?'list':'info').'/'.$parent_menu_model->menuid);
        if($this->input->post('mark')=="1")//修改
        {
            $contactModel->contact_id=$this->input->post('contact_id');
            $res= $this->Contact_model->update_contact($contactModel);
            if($res>0)
            {
                $this->ajaxmsgmodel->Msg='修改成功';
                $this->ajaxmsgmodel->Statu='ok';
                $this->ajaxmsgmodel->BackUrl=$back_url;
            }
            else
            {
                $this->ajaxmsgmodel->Msg='修改失败';
                $this->ajaxmsgmodel->Statu='err';
            }
        }else{//添加
            $res= $this->Contact_model->add_contact($contactModel);
            if($res>0)
            {
                $this->ajaxmsgmodel->Msg='添加成功';
                $this->ajaxmsgmodel->Statu='ok';
                $this->ajaxmsgmodel->BackUrl=$back_url;
            }
            else
            {
                $this->ajaxmsgmodel->Msg='添加失败';
                $this->ajaxmsgmodel->Statu='err';
            }
        }
        echo(json_encode($this->ajaxmsgmodel));
    }

    public function delcontactmsg()
    {
        $this->ajaxmsgmodel->Type='4';
        $this->Ajax_Check($this->ajaxmsgmodel);

        $this->load->library('ajaxMsgModel');
        $contact_id=$this->uri->segment(4);
        $contact_model=$this->Contact_model->get_contact_by_id($contact_id);
        $parent_menu_model=$this->Menu_model->get_menu_by_id($contact_model->menuid);
        $back_url=site_url('admin/'.$parent_menu_model->menu_control.'/'.$parent_menu_model->menu_action.($parent_menu_model->page_type==1?'list':'info').'/'.$parent_menu_model->menuid);
        $res=$this->Contact_model->del_contact($contact_id);
        if($res>0)
        {
            $this->ajaxmsgmodel->Msg='删除成功';
            $this->ajaxmsgmodel->Statu='ok';
            $this->ajaxmsgmodel->BackUrl=$back_url;
        }
        else
        {
            $this->ajaxmsgmodel->Msg='删除失败';
            $this->ajaxmsgmodel->Statu='err';
        }
        echo(json_encode($this->ajaxmsgmodel));
    }


    public function contactinfo()
    {
        $this->ajaxmsgmodel->Type='1';
        $this->Ajax_Check($this->ajaxmsgmodel);

        $menuid=$this->uri->segment(4);
        $data['menuid']=$menuid;
        $data['crumbs_items']=$this->get_crumbs_content_menu($menuid);
        $data['contentsModel']=$this->Contents_model->get_first_row_by_menuid($menuid);
        $this->load->view('admin/contents/contentsinfo.html',$data);
    }
}
?>